package com.ecommerce.dal.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.ecommerce.dal.dao.IPhotoDAO;
import com.ecommerce.dal.entity.Photo;
import com.ecommerce.dal.util.CustomHibernateDAOSupport;

@Repository("photoDAO")
public class PhotoDAO extends CustomHibernateDAOSupport implements IPhotoDAO {

	@Override
	public void save(Photo photo) {
		getHibernateTemplate().save(photo);

	}

	@Override
	public void update(Photo photo) {
		getHibernateTemplate().update(photo);

	}

	@Override
	public void delete(Photo photo) {
		getHibernateTemplate().delete(photo);

	}

	@Override
	public Photo findByPhotoId(long photoId) {
		List list = getHibernateTemplate().find(
				"from Photo photo where photo.photoId=?", photoId);
		return (Photo) ((list != null && list.size()>0) ?  list.get(0) : null) ;
	}

}
